import { Component, OnInit, ChangeDetectionStrategy, Input } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { uuid } from '@antv/x6/lib/util/string/uuid';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { TypeFrom } from 'src/app/component/basic';
import { WFVoice } from '../type';

@Component({
  selector: 'wf-add-voice-trigger',
  templateUrl: './add-voice-trigger.component.html',
  styleUrls: ['./add-voice-trigger.component.less'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class AddVoiceTriggerComponent implements OnInit {
  form!: FormGroup;

  @Input() voice!: WFVoice;

  constructor(
    private fb: FormBuilder,
    private modalRef: NzModalRef,
  ) {
    this.form = this.fb.group({
      id: [uuid(), [Validators.required]],
      value: [null, [Validators.required]],
      from: [TypeFrom.Voice]
    });
  }

  ngOnInit(): void {
    if (this.voice) {
      this.form.patchValue(this.voice);
    }
  }

  submit() {
    this.modalRef.destroy(this.form.value);
  }
}
